﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.Collections.Generic;

namespace W7Toshil.DataAccess
{
    public class BaseDao<T>
    {
        protected string EXPENSE = "EXPENSE";
        public void Save(T entity, string key)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

            IList<T> entitySet = null;

            if (!settings.TryGetValue<IList<T>>(key, out entitySet))
            {
                entitySet = new List<T>();
            }

            

            entitySet.Add(entity);

            settings[key] = entitySet;
            settings.Save();

        }

        public   IList<T> FetchAll(string key)
        {
            IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

            IList<T> entitySet = null;

            if (!settings.TryGetValue<IList<T>>(key, out entitySet))
            {
                entitySet = new List<T>();
            }

            return entitySet;
        }

        
    }
}
